package com.models;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import lombok.Getter;
import lombok.Setter;

@Entity
public class User {

	public static final String cLogin = "login";
	public static final String cPassw = "password";
	public static final String cEmail = "email";
	public static final String cSpace = "space";
	
	@Id @GeneratedValue
	@Getter private int id;
	
	@Column(name=cLogin, nullable=false, unique=true) 
	@Getter @Setter private String login;
	
	@Column(name=cPassw, nullable=false) 
	@Getter @Setter private String password;
	
	@Column(name=cEmail, nullable=true)  
	@Getter @Setter private String email;
	
	@Column(name=cSpace, nullable=false) 
	@Getter @Setter private float space = 100;
	
	@OneToMany(targetEntity=Shared.class, mappedBy="viewerUser")
	@Getter @Setter private List<Shared> viewerFolders;
	
	public User() {
		// TODO Auto-generated constructor stub
	}
	
	public User(String login, String password, String email) {
		this.login = login;
		this.password = password;
		this.email = email;
	}
	
	@Override
	public String toString() {
		String res = "--- Login: " + login + " Pass: " + password + " Email: " + email +
				" Limit: " + space + " ViewerFolders: ";
		for (Shared s : viewerFolders)
			res += s.getOwnerUser().getLogin() + "." + s.getFolder() + ", ";
		return res.substring(0, res.length()-2) + "---";
	}
		
}
